const app = getApp();
var {Api} = require('../../api/api')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    clicidata666:{//传递属性
      type:Object,
      value:{}
    },
    show:{
      type:Boolean,
      value:false,
      observer: 'showwatch1',
    },
    type:{//1设置2回复相应数字进群3是题库会员使用激活码
      type:Number,
      value:'',
      observer:'bindtyp1'
    },
    gonggongqun:{//公共群开关
      type:Boolean,
      value:false
    },
    vipqun:{//公共群开关
      type:Boolean,
      value:false
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    yin:false,//音效选择
    she:false,//答对了选项
    answer:false,//答案模糊选项
    code:'',//内用
    can:'',
    domain: Api.domain
  },
  

  attached(){
    console.log('12312');
    this.setData({
      can: wx.$cache.get('can')
    })      
    let viptime=new Date(wx.$cache.get('userinfo')?.vip_time.replace(/\-/g, '/')).getTime();
    let today=new Date().getTime()
    if(viptime>today){
      this.setData({
        vipqun:true
      })
    }

  },
  /**
   * 组件的方法列表
   */
  methods: {
    //数据变化显示
  showwatch1(newDate, oldDate){
    console.log("show11121121214444");
    this.setData({
      can: wx.$cache.get('can')
    })  
  },


    clog(){ //直接下载
      this.close();
       this.triggerEvent("clog",this.properties.clicidata666);
    },
    goen(){
      wx.navigateTo({
        url: '/pages/entergroup/entergroup',
      })
    },
    close(){
      this.setData({
        show:false
      })
      if(this.data.type == 2){
        console.log(666)
        wx.navigateBack({
          delta: 1,
        })
      }
      if(this.data.type==1){
        if(wx.$cache.get('she')){
          this.setData({
            she:true
          })
        }else{
          this.setData({
            she:false
          })
        }
        if(wx.$cache.get('yin')){
          this.setData({
            yin:true
          })
        }else{
          this.setData({
            yin:false
          })
        }
        if(wx.$cache.get('answer')){
          this.setData({
            answer:true
          })
        }else{
          this.setData({
            answer:false
          })
        }
      }
      this.triggerEvent('close')
    },
    bindtyp1(newDate, oldDate){
      console.log(newDate,oldDate)
      if(newDate==1){
        if(wx.$cache.get('she')){
          this.setData({
            she:true
          })
        }else{
          this.setData({
            she:false
          })
        }
        if(wx.$cache.get('yin')){
          this.setData({
            yin:true
          })
        }else{
          this.setData({
            yin:false
          })
        }
        if(wx.$cache.get('answer')){
          this.setData({
            answer:true
          })
        }else{
          this.setData({
            answer:false
          })
        }
      }
    },
    qie(){//音效切换
      this.setData({
        yin:!this.data.yin
      })
    },
    qie2(){//答对了下一题切换
      this.setData({
        she:!this.data.she
      })
    },
    qie3(){//答案模糊切换
      this.setData({
        answer:!this.data.answer
      })
    },
    btn(){//确定
      wx.$cache.set('yin',this.data.yin)
      wx.$cache.set('she',this.data.she)
      wx.$cache.set('answer',this.data.answer)
      this.close()
    },
    bindcode(e){
      this.setData({
        code:e.detail.value
      })
    },
    btn3(){//激活码确定
      var that = this
    var params = {
      code:this.data.code
    }
    wx.$http.get(wx.$get.activation_code,params).then(res=>{
      console.log('使用激活码',res)
      that.triggerEvent('init')
      wx.showToast({
        title: '使用成功',
        icon: 'none',
        duration: 1500,
      })
      wx.navigateTo({
        url: '/pages/entergroup/entergroup',
      })
    })
    },
    huoqu(){//如何获取激活码
      app.globalData.content = wx.$cache.get('can').get_activation_code
      wx.navigateTo({
        url: '/pages/waparse/waparse?title=如何获取激活码' + '&is_url=' + 2,
      })
    },
  }
})
